var util = require('../../../util/util.js');
var app = getApp();
Page({
    data: {
        movie: {}
    },
    onLoad: function(options) {
        var id = options.id;
        var url = app.globalData.doubanBase +
            "/v2/movie/subject/" + id;
        util.http(url, this.deal);
    },
    deal: function(data) {
        if (!data) {
            return
        }
        var director = {
            avator: '',
            name: '',
            id: ''
        }
        if (data.directors[0] != null) {
            if (data.directors[0].avators != null) {
                director.avator = data.directors[0].avators.large
            }
            director.name = data.directors[0].name;
            director.id = data.directors[0].id;
        }
        var movie = {
            movieImg: data.images ? data.images.large : "",
            country: data.countries[0],
            title: data.title,
            originalTitle: data.original_title,
            wishCount: data.wish_count,
            commentCount: data.comments_count,
            year: data.year,
            generes: data.genres.join("、"),
            stars: util.convertToStarsArray(data.rating.stars),
            score: data.rating.average,
            director: director,
            casts: util.convertToCastString(data.casts),
            castsInfo: util.convertToCastInfos(data.casts),
            summary: data.summary
        }
        this.setData({
          movie:movie
        });
        wx.setNavigationBarTitle({
          title:data.title
        });
    },
      proview: function (event) {
    var src = event.currentTarget.dataset.src;
    wx.previewImage({
      current: src, 
      urls: [src] 
    })
  }
})